package com.hdax.dmw.user.config.globalexception;

import com.hdax.dmw.exceptions.user.LoginException;
import com.hdax.dmw.exceptions.user.TokenException;
import com.hdax.dmw.utils.Result;
import com.hdax.dmw.utils.ResultGenerator;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(value = LoginException.class)
    public Result itemExceptionHandler(LoginException e){
        return ResultGenerator.genErrorResult(e);
    }

    @ExceptionHandler(value = TokenException.class)
    public Result tokenExceptionHandler(TokenException e){
        return ResultGenerator.genErrorResult(e);
    }

    @ExceptionHandler
    public Result loginExceptionHandler(Exception e){
        if(e instanceof NullPointerException){
            return null;
        }
        return null;
    }
}
